package cn.edu.zafu.bigdata.x.zyy2;

// Vehicle.java
class Vehicle {
    // 父类的move()方法
    public void move() {
        System.out.println("Vehicle is moving");
    }
}

// Car.java
class Car extends Vehicle {
    // 子类Car重写move()方法
    @Override
    public void move() {
        System.out.println("Car is moving");
    }
}

// Bicycle.java
class Bicycle extends Vehicle {
    // 子类Bicycle重写move()方法
    @Override
    public void move() {
        System.out.println("Bicycle is moving");
    }
}

// TestPolymorphism.java
public class TestPolymorphism {
    public static void main(String[] args) {
        // 定义一个Vehicle数组，存储Car和Bicycle对象
        Vehicle[] vehicles = new Vehicle[2];
        vehicles[0] = new Car();
        vehicles[1] = new Bicycle();

        // 调用它们的move()方法，展示多态性
        for (Vehicle vehicle : vehicles) {
            vehicle.move();
        }
    }
}
